<?php
class Period extends AppModel {
	public $name = 'Period';
	public 	$useTable  = 'periods';
	
	
	function getListPeriods(){
		return $this->find('all');
	}
	
	function getPeriodById($id){
		return $this->find('all',array(
			'conditions' => array(
				'id' => $id
			)
		));
	}
	function getPeriodsByHeroId($id){
		$query =" 	SELECT
						periods.id,
						periods.year_started,
						periods.year_ended,
						periods.period_name,
						periods.decscription,
						periods.image_url
					FROM
						periods ,
						heroes_periods ,
						heroes
					WHERE
						periods.id =  heroes_periods.period_id AND
						heroes_periods.hero_id =  heroes.id AND
						heroes.id =  '".$id."'";
		return $this->query($query);
	}
	
	function getPeriodsByName($name){
		return $this->find('all',array(
			'conditions' => array(
				'period_name like' => '%'.$name.'%'
			)
		));
	}
}